package chess;

/**the Board class is simply a 2d array of piece objects. Later a text file will 
 be added to create an initial board with a FileReader. the setPiece function
 will set the piece at the specified indices. getPiece will be passed to integers
 and return the piece at the coordinates, removePiece will ask for a 
 index and set the piece to null.
 * @author davondunajski
 * @author Anthony Hilyard
 */
public class Board
{
    private final Piece [][] chessboard;
    
    public Board ( )
    {
        chessboard = new Piece [8][8];
         
        initializeBoard();         
    }
    
    public void initializeBoard()
    {
        setPiece(0,0, new Rook(0));
        setPiece(1,0, new Knight(0));
        setPiece(2,0, new Bishop(0));
        setPiece(3,0, new Queen(0));
        setPiece(4,0, new King(0));
        setPiece(5,0, new Bishop(0));
        setPiece(6,0, new Knight(0));
        setPiece(7,0, new Rook(0));

        setPiece(0,7, new Rook(1));
        setPiece(1,7, new Knight(1));
        setPiece(2,7, new Bishop(1));
        setPiece(3,7, new Queen(1));
        setPiece(4,7, new King(1));
        setPiece(5,7, new Bishop(1));
        setPiece(6,7, new Knight(1));
        setPiece(7,7, new Rook(1));

        for(int x = 0; x < 8; x++)     
            setPiece(x, 1, new Pawn(0));            

        for(int x = 0; x < 8; x++)             
           setPiece(x, 6, new Pawn(1));    
    }
    
    public void setPiece(int xCoordinate, int yCoordinate, Piece pieceType)
    {
        chessboard[xCoordinate][yCoordinate] = pieceType;
    }
    
    public Piece getPiece(int xCoordinate, int yCoordinate)
    {
        return chessboard[xCoordinate][yCoordinate];
    }
    
    public void removePiece(int xCoordinate, int yCoordinate)
    {
        chessboard[xCoordinate][yCoordinate] = null;
    }
    
    public Board getCopy()
    {
        Board copy = new Board();
        for (int column = 0; column < 8; column++)
        {
            for (int row = 0; row < 8; row++)                
            {
                copy.setPiece(column, row, this.getPiece(column, row));
            }
        }
        
        return copy;
    }
}   
